﻿using System;
using System.Web.Mvc;

namespace TidyBlog.MVC
{
    /// <summary>
    /// 对所有提交的字符串进行Trim操作的ModelBinder
    /// </summary>
    public class StringTrimModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var value = base.BindModel(controllerContext, bindingContext);
            return value is string ? (value as string).Trim() : value;
        }
    }
}